var api = require('../../utils/api.js')
var app = getApp();

Page({
    data: {
        user:{},
        hasUserInfo:false
    },
    onLoad() {

        
    },
    /**
    * 生命周期函数--监听页面显示
    */
    onShow: function () {
      try {
        var user = wx.getStorageSync('user')
        if (user) {
          this.setData({ user: user });
        }
      } catch (e) {
        api.login();
      }

      try {
        var hasUserInfo = wx.getStorageSync('hasUserInfo')
        if (user) {
          this.setData({ hasUserInfo: hasUserInfo });
        }
      } catch (e) {

      }
    },
    /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
    onPullDownRefresh: function () {
      this.getUserInfo();
      wx.stopPullDownRefresh();

    },
    /**
      * 获取用户信息
      */
    getUserInfo: function () {
      var that = this;
      api.get({
        url: 'wxapp/user/getUser',
        success: function (res) {
          console.log(res)

          if (res.code) {

            that.setData({
              user: res.data,
              hasUserInfo:true
            })

            wx.setStorageSync('user', res.data);
            wx.setStorageSync('hasUserInfo', true);
          } else {
            wx.showToast({
              title: res.msg,
              icon: 'error',
              duration: 1000
            });
          }
        }
      })
    },
    /**
     * 跳转绑定手机
     */
  bindingTel:function(e){
    console.log(e)
    var form_id = e.detail.formId;
    //保存form_id
    app.cacheFormIDs(form_id);

    wx.navigateTo({
      url: '/pages/bindingTel/bindingTel',
    })
  },
  /**
   * 查看层级
   */
  checkLevel:function(e){
    console.log(e)
    var form_id = e.detail.formId;
    //保存form_id
    app.cacheFormIDs(form_id);

    wx.navigateTo({
      url: '/pages/checkLevel/checkLevel',
    })
  },
  /**
   * 跳转余额详情
   */
  getBalanceDetail:function(e){
    console.log(e)
    var form_id = e.detail.formId;
    //保存form_id
    app.cacheFormIDs(form_id);

    wx.navigateTo({
      url: '/pages/balanceDetail/balanceDetail',
    })
  }
});